package com.dmpp.mes.service.impl;


import com.dmpp.mes.bean.RespEnum;
import com.dmpp.mes.bean.ResponseData;
import com.dmpp.mes.dao.AromaMapper;
import com.dmpp.mes.dao.RawMaterialMapper;
import com.dmpp.mes.parameterInfo.Aroma;
import com.dmpp.mes.parameterInfo.RawMaterial;
import com.dmpp.mes.service.AromaService;
import com.dmpp.mes.service.RawMaterialService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service(value = "RawMaterialService")

public class RawMaterialServiceImpl implements RawMaterialService {

    @Autowired
    private RawMaterialMapper mapper;

    @Override
    public ResponseData findAll(RawMaterial rawMaterial) {
        ResponseData responseData = new ResponseData();
        PageInfo pageInfo = new PageInfo<>(mapper.findAll(rawMaterial));
        responseData.setData(pageInfo);
        return responseData;
    }

    @Override
    public ResponseData findById(String id) {
        ResponseData responseData = new ResponseData();
        responseData.setData(mapper.findById(id));
        return responseData;
    }

    @Override
    public ResponseData insert(RawMaterial rawMaterial) {
        ResponseData responseData = new ResponseData();
        RawMaterial rawMaterial1= mapper.findById(rawMaterial.getId());
        if (rawMaterial1==null){
            mapper.insert(rawMaterial);
        }else {
            responseData.setCodeEnum(RespEnum.ERROR2001);
        }
        return responseData;
    }

    @Override
    public ResponseData updateById(RawMaterial rawMaterial) {
        ResponseData responseData = new ResponseData();
        mapper.updateById(rawMaterial);
        return responseData;
    }

    @Override
    public ResponseData deleteById(String id) {
        ResponseData responseData = new ResponseData();
        mapper.deleteById(id);
        return responseData;
    }

    @Override
    public ResponseData altogether(RawMaterial rawMaterial) {
        ResponseData responseData = new ResponseData();
        responseData.setData(mapper.altogether(rawMaterial));
        return responseData;
    }
}
